#include<bits/stdc++.h>
#define int long long
#define N 1010
#define mod 1000000007
using namespace std;

int n, ans;
int a[N], b[N];
bool vis1[N], vis2[N];
vector<int>c;
map<vector<int>, bool>f;

int Len1 = 1, Len2 = 1;
void dfs(int k) {
	if(k > 2 * n - 2) {
		//cout << "look : ";
		//for(auto x : c) cout << x << " ";
		//cout << endl;
		if(!f.count(c)) {
			f[c] = 1;
			ans++;
		}
		return;
	}
	
	if(Len2 < n) {
		c.push_back(a[Len1]);
		Len2++;
		dfs(k + 1);
		c.pop_back();
		Len2--;
	}
	if(Len1 < n) {
		c.push_back(b[Len2]);
		Len1++;
		dfs(k + 1);
		c.pop_back();
		Len1--;
	}
}
int F[N];
signed main() {
	freopen("zha.in", "r", stdin);
	freopen("zha.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	if(n > 10) {
		F[0] = F[1] = 1;
		for(int i = 2; i < n; i++) 
		for(int j = 0; j < i; j++)
			F[i] = (F[i] + F[j] * F[i - j - 1] % mod) % mod;
		cout << F[n - 1];
		return 0;
	}
	dfs(1); 
	cout << ans;
	return 0;
}

/*
1
1 
1
*/

/*
2
1 2
2 1
*/


// 
/*
2
1 2
2 1
*/

/*
3
1 2 3
2 3 1
*/

/*
5
3 1 4 2 5
3 2 4 1 5
*/
